from wormbane.model.item import Item
from wormbane.util.format import material_adjective

class Weapon(Item):
    is_weapon = True
    attack = 0
    damage = 0
    beatitude = 'random'
    enchantable = True
    enchantment = 'random'
    char = ')'
    desc_attrs = ('beatitude_prefix', 'enchantment_prefix',
                  'handedness_prefix', 'material_prefix', 'kind')
    handedness = 'main-handed'
    material = 'steel'

    def __init__(self, **kwargs):
        kwargs.setdefault('material', default_weapon_material(kwargs['kind']))
        Item.__init__(self, **kwargs)

    @property
    def any_handed(self):
        return self.handedness == 'any-handed'

    @property
    def main_handed(self):
        return self.handedness == 'main-handed'

    @property
    def two_handed(self):
        return self.handedness == 'two-handed'

    @property
    def handedness_prefix(self):
        if self.two_handed:
            yield 'two-handed'

    @property
    def material_prefix(self):
        if self.material != default_weapon_material(self.kind):
            yield material_adjective(self.material)

def default_weapon_material(kind):
    return 'wood' if kind in ('club', 'staff') else 'steel'
